﻿using System;
using System.Data;
using System.Collections.Generic;
using Maticsoft.Common;
using Ajax.Model;
namespace Ajax.BLL
{
	/// <summary>
	/// Solutions
	/// </summary>
	public partial class Solutions
	{
		private readonly Ajax.DAL.Solutions dal = new Ajax.DAL.Solutions();
		public Solutions()
		{ }
		#region  Method

		/// <summary>
		/// 得到最大ID
		/// </summary>
		public int GetMaxId()
		{
			return dal.GetMaxId();
		}

		/// <summary>
		/// 是否存在该记录
		/// </summary>
		public bool Exists(int ID)
		{
			return dal.Exists(ID);
		}

		/// <summary>
		/// 增加一条数据
		/// </summary>
		public bool Add(Ajax.Model.Solutions model)
		{
			return dal.Add(model);
		}

		/// <summary>
		/// 更新一条数据
		/// </summary>
		public bool Update(Ajax.Model.Solutions model)
		{
			return dal.Update(model);
		}

		/// <summary>
		/// 删除一条数据
		/// </summary>
		public bool Delete(int ID)
		{

			return dal.Delete(ID);
		}
		/// <summary>
		/// 删除一条数据
		/// </summary>
		public bool DeleteList(string IDlist)
		{
			return dal.DeleteList(IDlist);
		}

		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public Ajax.Model.Solutions GetModel(int ID)
		{

			return dal.GetModel(ID);
		}

		/// <summary>
		/// 得到一个对象实体，从缓存中
		/// </summary>
		public Ajax.Model.Solutions GetModelByCache(int ID)
		{

			string CacheKey = "SolutionsModel-" + ID;
			object objModel = Maticsoft.Common.DataCache.GetCache(CacheKey);
			if (objModel == null)
			{
				try
				{
					objModel = dal.GetModel(ID);
					if (objModel != null)
					{
						int ModelCache = Maticsoft.Common.ConfigHelper.GetConfigInt("ModelCache");
						Maticsoft.Common.DataCache.SetCache(CacheKey, objModel, DateTime.Now.AddMinutes(ModelCache), TimeSpan.Zero);
					}
				}
				catch { }
			}
			return (Ajax.Model.Solutions)objModel;
		}

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetList(string strWhere)
		{
			return dal.GetList(strWhere);
		}
		/// <summary>
		/// 获得数据列表
		/// </summary>
		public List<Ajax.Model.Solutions> GetModelList(string strWhere)
		{
			DataSet ds = dal.GetList(strWhere);
			return DataTableToList(ds.Tables[0]);
		}
		/// <summary>
		/// 获得数据列表
		/// </summary>
		public List<Ajax.Model.Solutions> DataTableToList(DataTable dt)
		{
			List<Ajax.Model.Solutions> modelList = new List<Ajax.Model.Solutions>();
			int rowsCount = dt.Rows.Count;
			if (rowsCount > 0)
			{
				Ajax.Model.Solutions model;
				for (int n = 0; n < rowsCount; n++)
				{
					model = new Ajax.Model.Solutions();
					if (dt.Rows[n]["ID"] != null && dt.Rows[n]["ID"].ToString() != "")
					{
						model.ID = int.Parse(dt.Rows[n]["ID"].ToString());
					}
					if (dt.Rows[n]["Title"] != null && dt.Rows[n]["Title"].ToString() != "")
					{
						model.Title = dt.Rows[n]["Title"].ToString();
					}
					if (dt.Rows[n]["UpdateTime"] != null && dt.Rows[n]["UpdateTime"].ToString() != "")
					{
						model.UpdateTime = DateTime.Parse(dt.Rows[n]["UpdateTime"].ToString());
					}
					if (dt.Rows[n]["Description"] != null && dt.Rows[n]["Description"].ToString() != "")
					{
						model.Description = dt.Rows[n]["Description"].ToString();
					}
					if (dt.Rows[n]["ClassID"] != null && dt.Rows[n]["ClassID"].ToString() != "")
					{
						model.ClassID = int.Parse(dt.Rows[n]["ClassID"].ToString());
					}
					if (dt.Rows[n]["ShowInIndex"] != null && dt.Rows[n]["ShowInIndex"].ToString() != "")
					{
						model.ShowInIndex = int.Parse(dt.Rows[n]["ShowInIndex"].ToString());
					}
					if (dt.Rows[n]["ShowInClass"] != null && dt.Rows[n]["ShowInClass"].ToString() != "")
					{
						model.ShowInClass = int.Parse(dt.Rows[n]["ShowInClass"].ToString());
					}
					modelList.Add(model);
				}
			}
			return modelList;
		}

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetAllList()
		{
			return GetList("");
		}

		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public int GetRecordCount(string strWhere)
		{
			return dal.GetRecordCount(strWhere);
		}
		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public DataSet GetListByPage(string strWhere, string orderby, int startIndex, int endIndex)
		{
			return dal.GetListByPage(strWhere, orderby, startIndex, endIndex);
		}
		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		//public DataSet GetList(int PageSize,int PageIndex,string strWhere)
		//{
		//return dal.GetList(PageSize,PageIndex,strWhere);
		//}

		#endregion  Method
	}
}

